﻿using AntDesign.TableModels;
using Mapster;
using OpenIddict.Abstractions;
using OpenIddict.EntityFrameworkCore.Models;
using Org.BouncyCastle.Utilities.Collections;
using SageKing.Blazor.OpenIdService.Components.Application.Pages.Manage.Components;

namespace SageKing.Blazor.OpenIdService.Components.Application.Pages.Manage;

public partial class Index
{

    protected override async Task OnInitializedAsync()
    {
        try
        {
            TabTitle = "应用管理";
            await base.OnInitializedAsync();
        }
        catch (Exception ex)
        {
            Error?.ProcessError(ex);
        }
    }

    protected override Task OnAfterRenderAsync(bool firstRender)
    {
        try
        {
            TabTitle = "应用管理";
            return base.OnAfterRenderAsync(firstRender);
        }
        catch (Exception ex)
        {
            Error?.ProcessError(ex);
            return Task.CompletedTask;
        }
    }

    #region	Tool相关
    public override Task OnToolDefaultClickAsync(ToolEventArgs e)
    {
        return base.OnToolDefaultClickAsync(e);
    }
    #region CRUD
    public override string GetDisplayName(ApplicationViewModel model)
    {
        return model.DisplayName;
    }
    #endregion
    #endregion

    #region	Left

    public IndexLeft IndexLeftList { get; set; }
    public override async void OnLeftRowClick(RowData<ApplicationViewModel> data)
    {
        var row = data.Data;
        // _ = Message.InfoAsync($"You clicked {row.Id}:{row.DisplayName} row");
        EditModel = row.Clone<ApplicationViewModel>();
        //var getPwd = await EditForm.DataService.GetDetail(row.Id);
        EditModel.ClientSecret = "";

        // 密码不回显
        this.EditForm.Me.form.ValidationReset();
        await Task.CompletedTask;
    }
    #endregion
}
